package com.cy.milktea.controller;


import com.cy.milktea.pojo.Entremets;
import com.cy.milktea.pojo.System.JsonResult;
import com.cy.milktea.service.EntremetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;


@RestController
@RequestMapping("/entremets")
public class EntremetsController {

    @Autowired
    private EntremetsService entremetsService;

    @PostMapping
    public JsonResult add(Entremets entremets) throws IOException {
        entremetsService.add(entremets);
        return JsonResult.ok("添加成功!");
    }

    @DeleteMapping
    public JsonResult delete(Integer id,Integer force) {
        entremetsService.delete(id, force);
        return JsonResult.ok("删除成功!");
    }


    @PutMapping
    public JsonResult update(Entremets entremets) throws IOException {
        entremetsService.update(entremets);
        return JsonResult.ok("修改成功!");
    }

    @GetMapping
    public JsonResult query(String name, Integer status) {
        if(name != null) name = "".equals(name.trim()) ? null : name.trim();
        status = status == -1 ? null : status;
        return JsonResult.ok("查询成功!", entremetsService.query(name, status));
    }

}
